/*
 * Copyright (C) 2013 rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.ui.components;

import java.util.ArrayList;
import rpg.gfx.Bitmap;

/**
 *
 * @author rothens
 */
public class ComponentPanel extends Component implements ISubcomponentHolder {
    public Bitmap active;
    public Bitmap inactive;
    public Bitmap hover;
    
    ArrayList<Component> subcomponents = new ArrayList<Component>();
    int active_c = -1;

    public ComponentPanel(int width, int height, Integer x, Integer y) {
        super(width, height, x, y);
        active = new Bitmap(width, height);
        inactive = new Bitmap(width, height);
        hover = new Bitmap(width, height);
        active.clearWith(0xaa000001);
        inactive.clearWith(0xaa000001);
        hover.clearWith(0xaa000001);
        
        
        StaticTextures.border_active.overlay(active);
        StaticTextures.border_inactive.overlay(inactive);
        StaticTextures.border_hover.overlay(hover);
    }
    
    

    @Override
    public void redraw() {
        clear();
        switch(state){
            case HOVER:
                draw(hover, 0, 0);
                break;
            case INACTIVE:
                draw(inactive, 0, 0);
                break;
            case SELECTED:
                draw(active, 0, 0);
        }
        for(Component c : subcomponents){
            //c.redraw();
            draw(c, c.getX(), c.getY());
        }
        if(parent != null){
            ((Component)parent).redraw();
        }
    }

    @Override
    public void setActive(int i) {
        active_c = i;
    }

    @Override
    public void setState(ComponentState state) {
        super.setState(state);
        if(state == ComponentState.INACTIVE){
            for(Component c: subcomponents){
                c.setState(state);
            }
        }
    }
    
    

    @Override
    public int getXDiff() {
        return 0;
    }

    @Override
    public int getYDiff() {
        return 0;
    }

    @Override
    public ArrayList<Component> getSubComponents() {
        return subcomponents;
    }

    @Override
    public void addChild(Component child) {
        //child.setParent(this);
        subcomponents.add(child);
    }

    @Override
    public int getActive() {
        return active_c;
    }

    @Override
    public boolean isInsideSubcomponentArea(int x, int y) {
        return true;
    }
    
    
    
}
